import { Component, Input } from '@angular/core';
import { IonicPage, NavController, NavParams,ModalController ,LoadingController,ToastController,ViewController} from 'ionic-angular';
import {Storage} from '@ionic/storage'
import { BaseUI } from '../../commom/baseui';
import {RestProvider} from '../../providers/rest/rest';
import {DetailsPage} from '../../pages/details/details'


/**
 * Generated class for the QuestionListComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: 'question-list',
  templateUrl: 'question-list.html'
})
export class QuestionListComponent extends BaseUI{

  errorMessage: any;
  questions:string[];

  // 外部传入
  @Input('datatype') dataSourceType

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public modalCtrl: ModalController,
    public storage:Storage,
    public loadingCtrl: LoadingController,
    public rest: RestProvider,
    public toastCtrl: ToastController,
    public viewCtrl:ViewController) {
    super();
    
  }

  //这里没有ionViewDidLoad生命周期函数
  ngAfterContentInit(){
    this.storage.get('UserId').then((val) => {
      if (val != null) {
        //加载用户数据
        var loading = super.showLoading(this.loadingCtrl, "加载中...");
        this.rest.getUserQuestionList(val,this.dataSourceType)
          .subscribe(
          q => {
            this.questions = q;
            loading.dismissAll();
          },
          error => this.errorMessage = <any>error);
      }
    });


  }

  gotoDetails(questionId){
    this.navCtrl.push(DetailsPage,{id:questionId})

  }

}
